/*
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * This file is part of Harmattan SmashMiner OpenGL game application.
 * 
 * Harmattan SmashMiner OpenGL Example Application version 1.0.0
 *  
 * Latest update: 15.4.2011
 *
 * The Harmattan SmashMiner OpenGL example application demonstrates how to use 
 * the OpenGL ES in Harmattan devices.
 *
 * This example is provided as a starting point for 3rd party
 * developers (you) to ease the implementation of OpenGL based 
 * games. Ideas, parts of code or methodologies that this
 * example application uses can be freely used without restrictions.
 *
 * See file README.txt how to build and compile this example application
 * in the Harmattan SDK environment. 
 * 
 * See file INSTALL.txt to find out what is required to run this
 * application and how to install the application to the device or
 * alternatively in QEMU-emulator.
 *
 * The LICENSE.txt file explains the license this software is provided
 * with. A copy of the same license is included in this source file.
 * 
 */

/*
 * Copyright (C) 2011 by Nokia Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "shaderprograms.h"
#ifdef SMASHMINER_CONFIG_USE_OPENGL_ES_2

/*! \class spBase 
 *
 * Base class for managing SmashMiner shader progams. 
 *
 * Allows OpenGL shader programs to be linked and used.
 */

/*! \c spBase class constructor.
 *
 * \param vshader Vertex shader program
 * \param fshader Fragment shader program
 */
spBase::spBase(QGLShader *vshader, QGLShader *fshader) : QGLShaderProgram()
{
    addShader(vshader);
    addShader(fshader);

    link();

    matrixLoc = uniformLocation("matrix");
    vertexLoc = attributeLocation("vertex");
}

/*! \c spBase class destructor */
spBase::~spBase()
{
    removeAllShaders();
}

//////////////////////////////////////////////////////////////////////////

/*! \class spBackGround 
 *
 * Class for managing shader programs for rendering background graphics.
 */
spBackGround::spBackGround(QGLShader *vshader, QGLShader *fshader) 
    : spTexture(vshader, fshader)
{
}

//////////////////////////////////////////////////////////////////////////

/*! \class spBackGroundEff2D 
 *
 * Class for managing shader programs for rendering background graphics
 * with bomb and black hole effects.
 */
spBackGroundEff2D::spBackGroundEff2D(QGLShader *vshader, QGLShader *fshader) 
    : spBackGround(vshader, fshader)
{
    bombDataLoc = uniformLocation("bombdata");
    bhData3Loc = uniformLocation("bhdata3");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spConstantMaterial 
 *
 * Class for managing shader programs for rendering constant material
 * (unified colour) game objects.
 */
spConstantMaterial::spConstantMaterial(QGLShader *vshader, QGLShader *fshader)
    : spBase(vshader, fshader)
{
    lmAmbientLoc = uniformLocation("l_m_ambient");
    lmDiffuseLoc = uniformLocation("l_m_diffuse");
    lightDirLoc = uniformLocation("light_dir");
    normalLoc = attributeLocation("normal");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spConstantMaterialEff3D 
 *
 * Class for managing shader programs for rendering constant
 * material (unified colour) game objects with black hole effect.
 */
spConstantMaterialEff3D::spConstantMaterialEff3D(QGLShader *vshader, QGLShader *fshader) 
    : spConstantMaterial(vshader, fshader)
{
    bhData4Loc = uniformLocation("bhdata4");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spVariableMaterial 
 *
 * Class for managing shader programs for rendering variable material
 * (colour value for each vertex point) game objects.
 */
spVariableMaterial::spVariableMaterial(QGLShader *vshader, QGLShader *fshader) 
    : spConstantMaterial(vshader, fshader)
{
    materialLoc = attributeLocation("material");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spVariableMaterialEff3D 
 *
 * Class for managing shader programs for rendering variable 
 * material (colour value for each vertex point) game objects with black hole effect.
 */
spVariableMaterialEff3D::spVariableMaterialEff3D(QGLShader *vshader, QGLShader *fshader) 
    : spVariableMaterial(vshader, fshader)
{
    bhData4Loc = uniformLocation("bhdata4");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spParticles 
 *
 * Class for managing shader programs for rendering particle effects.
 */
spParticles::spParticles(QGLShader *vshader, QGLShader *fshader) 
    : spBase(vshader, fshader)
{
    pdataLoc = attributeLocation("pdata");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spParticlesEff2D 
 *
 * Class for managing shader programs for rendering particle effects with
 * black hole effect.
 */
spParticlesEff2D::spParticlesEff2D(QGLShader *vshader, QGLShader *fshader) 
    : spParticles(vshader, fshader)
{
    bhData3Loc = uniformLocation("bhdata3");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spTexture 
 *
 * Class for managing shader programs for rendering texture objects.
 */
spTexture::spTexture(QGLShader *vshader, QGLShader *fshader) 
    : spBase(vshader, fshader)
{
    texCoordLoc = attributeLocation("texcoord");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spTextureEff3D 
 *
 * Class for managing shader programs for rendering texture objects with black hole effect.
 */
spTextureEff3D::spTextureEff3D(QGLShader *vshader, QGLShader *fshader) : spTexture(vshader, fshader)
{
    bhData4Loc = uniformLocation("bhdata4");
}

//////////////////////////////////////////////////////////////////////////

/*! \class spControlGauges 
 *
 * Class for managing shader programs for rendering control cauges.
 */
spControlGauges::spControlGauges(QGLShader *vshader, QGLShader *fshader) 
    : spBase(vshader, fshader)
{
}

//////////////////////////////////////////////////////////////////////////

/*! \class spRewindGauge 
 *
 * Class for managing shader programs for rendering the rewind cauge.
 */
spRewindGauge::spRewindGauge(QGLShader *vshader, QGLShader *fshader) 
    : spBase(vshader, fshader)
{
}

#endif  // SMASHMINER_CONFIG_USE_OPENGL_ES_2
